//microcommand define pygmentize
inject(["puppeteer"])
signature("<lexer:string> <code:rawtext>")
action(async (_, lexer, code) => {
const execa = require("execa")
let html=""
try{
html = (await execa.command("pygmentize -f html -l " + lexer + " -O encoding=utf8", { input: code })).stdout + "<style>:root{background:#0a0a0a}body{display:inline-block}pre{font-family:monospace;max-width:50rem;white-space:pre-wrap;overflow-wrap:break-word}" + (await execa.command("pygmentize -f html -S one-dark")).stdout
}catch(e){return String(e)}
const p=await ctx.puppeteer.page()
p.setContent(html)
return h.image(await p.screenshot({clip:await (await p.$ ("body")).boundingBox()}), "image/png")
})
locale("zh-CN", { description: "Pygments 语法高亮" })